package Lee_code;

public class Lee_121_2 {
    public int maxProfit(int[] prices) {
        int max = -99999;
        int len = prices.length;
        int[][] dp = new int[len+1][2];

        dp[0][0] = -prices[0];
        dp[0][1] = 0;

        // int[][0] 不卖当前股票, int[][1]卖出当前股票
        for(int i=0; i<len; i++){

            dp[i][0] = Math.max(-prices[i], dp[i-1][0]);
            if (prices[i]-dp[i-1][0]>dp[i-1][1]) {
                dp[i][1] = prices[i] - dp[i - 1][0];
                dp[i][0] = -prices[i];

            }

        }
        return dp[len][1];
    }
}
